package com.longrise.android.widget.lviewpage;

import android.content.Context;

import com.longrise.LEAP.Base.Objects.EntityBean;
import com.longrise.LWFP.BLL.Mobile.Object.WMBModule;
import com.longrise.LWFP.BLL.Mobile.Object.WMBRunningData;

public class LWFlowUtil {
	private WMBRunningData wmbRunningData = null;
	private EntityBean[] entityBeans = null;
	
	public LWFlowUtil(WMBRunningData wmbRunningData) {
		this.wmbRunningData = wmbRunningData;
	}
	
	public boolean isShow(String string)
	{
		boolean b = true;
		if(null == string)
		{
			return false;
		}
		if(null == entityBeans)
		{
			entityBeans = getModuleOptions();
		}
		if(null != entityBeans)
		{
			for (int i = 0; i < entityBeans.length; i++) {
				EntityBean bean = entityBeans[i];
				if(null != bean)
				{
					if(string.equals(bean.get("content", "")))
					{
						b = false;
					}
				}
			}
		}
		
		return b;
	}
	
	public EntityBean[] getModuleOptions()
	{
		WMBModule wmbModule = null;
		String string = null;
		EntityBean[] entityBeans = null;
		String[] strings = null;
		
		if(null == wmbRunningData){
			return null;
		}
		wmbModule = wmbRunningData.getModule();
		if(null == wmbModule){
			return null;
		}
		string = wmbModule.getModuleOptions();
		if(null == string || "".equals(string))
		{
			return null;
		}
		strings = string.split(",");
		entityBeans = new EntityBean[strings.length];
		if(null != strings && null != entityBeans)
		{
			
			for (int i = 0; i < strings.length; i++) {
				String content = null;
				String mark = null;
				EntityBean bean = new EntityBean();
				if(null != strings[i])
				{
					String[] strings2 = strings[i].split(":");
					if(null != strings2 && strings2.length >= 2)
					{
						content = strings2[0];
						mark = strings2[1];
						bean.put("content", content);
						bean.put("mark", mark);
					}
					strings2 = null;
				}
				entityBeans[i] = bean;
				content = null;	
				mark = null;
				bean = null;
			}
		}
		wmbModule = null;
		string = null;
		strings = null;
		
		return entityBeans;
		
	}

	public void onDestory()
	{
		 wmbRunningData = null;
		 entityBeans = null;
	}
	
	/**
	 * convert the px value to dip value
	 * 
	 * @param context
	 * @param dipValue
	 * @return
	 */
	public static int px2dip(Context context, float pxValue) {
		final float scale = context.getResources().getDisplayMetrics().density;
		return (int) (pxValue / scale + 0.5f);
	}
	/**
	 * convert the dip value to px value
	 * 
	 * @param context
	 * @param dipValue
	 * @return
	 */
	public static int dip2px(Context context, float dipValue) {
		float scale = context.getResources().getDisplayMetrics().density;
		return (int) (dipValue * scale + 0.5f);
	}
}
